package com.courseSchedulingSystem.mapper;

import com.courseSchedulingSystem.pojo.dto.StudentLoginDTO;
import com.courseSchedulingSystem.pojo.entity.Student;
import com.courseSchedulingSystem.pojo.vo.StudentLoginVO;
import org.apache.ibatis.annotations.*;

import java.util.List;
import java.util.Map;

@Mapper
public interface StudentMapper {
    @Select("select  id,stuName,stuRole from students where stuId = #{stuId} and stuPassword = #{stuPassword}")
    StudentLoginVO selectStudent(StudentLoginDTO studentLoginDTO);

    @Update("update students set stuPassword = #{newStuPassword} where stuId = #{stuId}")
    void upDatePassword(@Param("stuID") int stuId, @Param("newStuPassword") String newStuPassword);

    @Select("select * from students where stuId = #{stuId}")
    Student selectAllByStuId(int stuId);


    @Update("update sign_situation_for_student set signSituation = #{signSituation} where stuId = #{stuId} and signName = #{signName}")
    void upDataSignSituationForStudent(@Param("stuId") Integer stuId, @Param("signName") String signName, @Param("signSituation") Integer signSituation);

    // 获取当前学期信息
    @Select("SELECT year, term FROM semester WHERE current = 1")
    Map<String, String> getCurrentSemester();


    // 查询学生是否已经选课
    @Select("SELECT COUNT(*) FROM student_course WHERE userId = #{userId} AND courseId = #{courseId}")
    boolean isCourseSelected(@Param("userId") String userId, @Param("courseId") String courseId);

    // 查询课程已选人数
    @Select("SELECT COUNT(*) FROM student_course WHERE courseId = #{courseId}")
    int countEnrolledStudents(@Param("courseId") String courseId);

    // 插入选课记录
    @Insert("INSERT INTO student_course (userId, courseId) VALUES (#{userId}, #{courseId})")
    void insertEnrollment(@Param("userId") String userId, @Param("courseId") String courseId);

    // 删除选课记录
    @Delete("DELETE FROM student_course WHERE userId = #{userId} AND courseId = #{courseId}")
    void deleteEnrollment(@Param("userId") String userId, @Param("courseId") String courseId);
}
